import React from 'react';
import { Tag } from 'antd';
import { StateType } from '@/common-typings';
import constant from '@/const';
import { getMonthDate, getYearDate } from '@/utils/utils';
// import { getColumnSearchProps } from '@/components/CreateTable/utils';

export const getFormData = (that: StateType) => {
  const { submitLoading, exportLoading } = that.state;
  const formConfig = {
    submitLoading,
    exportLoading,
    config: [
      {
        id: 'test',
        type: 'monthPicker',
        options: {
          name: '月份',
          value: getMonthDate(),
          format: (value: any) => value.format('YYYY-MM'),
        },
      },
      {
        id: 'test123',
        type: 'yearPicker',
        options: {
          name: '年份',
          value: getYearDate(),
          format: (value: any) => value.format('YYYY-MM-DD'),
        },
      },
      {
        id: 'optType123',
        type: 'select',
        handle: (value: number) => that.selectChange(value),
        options: {
          name: '调整方式',
          placeholder: '请选择调整方式',
          value: [],
          allowClear: false,
          list: constant.LEVEL_ADJUST_TYPE,
          format: (list: any[]) => list.join(','),
        },
        config: {
          mode: 'multiple',
        },
      },
      {
        id: 'date',
        type: 'daterange',
        options: {
          name: '日期',
          showTime: true,
          value: that.initDefaultDate(7),
          allowClear: false,
          format: ['startTime', 'endTime'],
        },
      },
      {
        id: 'userType',
        type: 'select',
        options: {
          name: '',
          width: 100,
          placeholder: '',
          value: -1,
          hidden: true,
          allowClear: false,
          list: constant.LEVEL_ADJUST_TYPE,
        },
      },
      {
        id: 'creator',
        type: 'input',
        options: {
          name: '账户名',
          value: '',
          width: 260,
          placeholder: '请输入账户名',
          addonBefore: 'userType',
        },
      },
      {
        id: 'max',
        type: 'input-number',
        options: {
          name: '',
          width: 80,
          hidden: true,
          placeholder: '请输入',
          value: '',
        },
      },
      {
        id: 'min',
        type: 'input-number',
        options: {
          name: '',
          width: 80,
          hidden: true,
          placeholder: '请输入',
          value: '',
        },
      },
      {
        id: 'input-number-group',
        type: 'input-number-group',
        options: {
          name: '提现金额',
          value: '',
          prev: 'min',
          next: 'max',
        },
      },
      // {
      //   id: 'optType',
      //   type: 'select',
      //   handle: (value: number) => that.selectChange(value),
      //   options: {
      //     name: '调整方式',
      //     placeholder: '请选择调整方式',
      //     value: -1,
      //     allowClear: false,
      //     list: constant.LEVEL_ADJUST_TYPE,
      //   },
      // },
      // {
      //   id: 'creator',
      //   type: 'input',
      //   options: {
      //     name: '调整人',
      //     value: '',
      //     disabled: disableCreator,
      //     placeholder: '请输入调整人',
      //   },
      // },
      {
        id: 'userName',
        type: 'input',
        options: {
          name: '账户名',
          value: '',
          placeholder: '请输入账户名',
        },
      },
      {
        id: 'submit',
        type: 'button',
        options: {
          name: '查询',
          type: 'primary',
        },
      },
      {
        id: 'reset',
        type: 'button',
        options: {
          name: '重置',
        },
      },
      {
        id: 'export',
        type: 'button',
        handle: that.exportExcel,
        options: {
          name: '导出',
          type: 'primary',
        },
      },
    ],
    requestList: that.requestList,
  };
  // 此处保存表单最初的默认值
  that.initDefaultFormParams({ formConfig });
  return formConfig;
};

export const getTableData = (that: StateType) => {
  const { pagination, submitLoading, list, tableFilters } = that.state;
  return {
    pagination,
    loading: submitLoading,
    changePaginationCallBack: (param: StateType) => that.updatePagination(param, that.requestList),
    tableFiltersTool: that.tableFiltersTool,
    data: list || [],
    header: [
      {
        title: '调整时间',
        dataIndex: 'createTime',
        formatTimeStamp: true,
      },
      {
        title: '账户名',
        dataIndex: 'username',
      },
      {
        title: '调整前',
        dataIndex: 'optBeforeData',
      },
      {
        title: '调整后',
        dataIndex: 'optData',
      },
      {
        title: '调整方式',
        dataIndex: 'optDesc',
        filterMultiple: false,
        filteredValue: tableFilters.optType,
        filters: that.filtersLabelToText(constant.LEVEL_ADJUST_TYPE),
        formatStr: 'optType',
      },
      {
        title: '调整人',
        dataIndex: 'creator',
        filteredValue: tableFilters.creator,
        filterBindDataIndex: 'creator',
      },
      {
        title: '锁定状态',
        dataIndex: 'lockStatus',
        render: (text: number | string) => {
          if (text === 1) {
            return <Tag color="red">已锁定</Tag>;
          }
          return <Tag color="green">未锁定</Tag>;
        },
      },
    ],
  };
};
